package com.ming.springboot.controller;

import com.ming.other.vo.OtherBean;
import com.ming.springboot.annotation.profile.Person;
import com.ming.springboot.config.ApplicationUtil;
import com.ming.springboot.service.FooService;
import com.ming.springboot.vo.DemoBean;
import com.ming.springboot.vo.ManBean;
import com.ming.springboot.vo.SimpleBean;
import com.ming.springboot.vo.SomeBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Import;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by mqsi on 2022/5/9 14:42
 */
@RestController
@RequestMapping("beans")
@Import(SimpleBean.class)
public class BeanController {
	@Autowired
	private OtherBean otherBean;
	@Autowired
	private DemoBean demoBean;

//	@Autowired
//	private SomeBean someBean;
//
//	@Autowired
//	private SomeBean abc;

	@Autowired
	private ApplicationUtil applicationUtil;
	@Autowired
	private FooService fooService;
	@Autowired
	private Person person;
	@Autowired
	private ManBean manBean;
	@Autowired
	private SimpleBean simpleBean;

	@RequestMapping("/hello.action")
	public Object hello(){
		String other = otherBean.other();
		String demo = demoBean.sayHello();
		return "OtherBean say:" + other + ", DemoBean say:" + demo;
	}

	@RequestMapping("someBean.action")
	public Object someBean(){
		SomeBean so = applicationUtil.getApplicationContext().getBean(SomeBean.class);
		System.out.println(so.getName());
		return so.getName();
	}

	@RequestMapping("/getRepository.action")
	public Object getRepository(){
		return fooService.getFooRespository().getDataSource();
	}

	@RequestMapping("/person.action")
	public Object person(){
		person.speak();
		return "success";
	}

	@RequestMapping("/manBean.action")
	public Object manBean(){
		return manBean.getManName();
	}

	@RequestMapping("/simpleBean.action")
	public Object simpleBean(){
		return simpleBean.sayHello();
	}

	@RequestMapping("/error.action")
	public Object error(){
		int count = 1/0;
		return "success";
	}
}
